package com.caiyi.financial.nirvana.sms;

import com.alibaba.fastjson.JSON;
import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
import com.caiyi.financial.nirvana.sms.queue.SendQueueEntity;
import org.apache.commons.io.FileUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

import java.io.File;
import java.util.Date;
import java.util.List;

public class SendMsg {

    public static void main(String[] args) throws Exception {
        List<String> list = FileUtils.readLines(new File("C:\\Users\\lvcha.000\\Desktop\\sms_data\\0515.csv"), "utf-8");
        Jedis jedis = new Jedis("39.100.85.203", 8090);
        Pipeline line = jedis.pipelined();
        for (int i = 0; i < list.size(); i++) {
            String item = list.get(i);
            String[] strs = item.split(",");
            SendQueueEntity entity = new SendQueueEntity();
            entity.setAccessNumber(strs[0].replace("\"", ""));
            entity.setAccount(strs[1].replace("\"", ""));
            entity.setAction(1);
            entity.setBatchId(strs[2].replace("\"", ""));
            entity.setContent(strs[3].replace("\"", ""));
            entity.setGatewayId(Integer.parseInt(strs[4].replace("\"", "")));
            entity.setIp(strs[5].replace("\"", ""));
            entity.setMessageId(strs[6].replace("\"", ""));
            entity.setNum(Integer.parseInt(strs[7].replace("\"", "")));
            entity.setOperator(Integer.parseInt(strs[8].replace("\"", "")));
            entity.setPhone(strs[9].replace("\"", ""));
            entity.setPhoneCount(1);
            entity.setProductId(37);
            entity.setSendTime(new Date());
            entity.setStatus(1);
            String key = String.format(JedisKey.SMS_QUEUE_MARKETING_MSG_SEND, entity.getGatewayId());
            line.lpush(key, JSON.toJSONString(entity));
        }
        int count = line.syncAndReturnAll().size();
        System.out.println("=========================list size is : " + list.size() + ", success : " + count);
        jedis.close();
    }

}
